package com.fancy.social.controller;

import cn.hutool.db.PageResult;
import com.fancy.common.dto.response.Result;
import com.fancy.imasclient.dto.FollowInfoDTO;
import com.fancy.imasclient.dto.FollowRequestDTO;
import com.fancy.social.dto.FollowDTO;
import com.fancy.social.service.FollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/v1/follows")
public class FollowController {

    @Autowired
    private FollowService followService;

    @PostMapping
    public ResponseEntity<Void> follow(@RequestHeader("X-User-Id") Long userId, @RequestBody FollowDTO followDTO) {
        followService.follow(userId, followDTO);
        return ResponseEntity.ok().build();
    }

    @DeleteMapping
    public ResponseEntity<Void> unfollow(@RequestHeader("X-User-Id") Long userId, @RequestBody FollowDTO followDTO) {
        followService.unfollow(userId, followDTO);
        return ResponseEntity.ok().build();
    }

    /**
     * 获取用户关注统计信息
     */
    @GetMapping("/{userId}/stats")
    public Result<Map<String, Object>> getFollowStats(@PathVariable("userId") Long userId,
                                                     @RequestHeader(value = "X-User-Id", required = false) Long currentUserId) {
        Map<String, Object> stats = followService.getFollowStats(userId, currentUserId);
        return Result.success(stats);
    }
}
